using Cysharp.Threading.Tasks;
using System.IO;
using System.Threading.Tasks;
using UnityEngine;

namespace IQIGame.Onigao.GameAOT
{
    public static class LoadABUtility
    {

        public static UniTask<AssetBundle> LoadAb(string assetBundleName)
        {
            string path = Path.Combine(Application.persistentDataPath, assetBundleName);
            if(File.Exists(path))
            {
                return UniTask.FromResult(AssetBundle.LoadFromFile(path));
            }
            else
            {
                path = Path.Combine(Application.streamingAssetsPath, assetBundleName);
#if UNITY_EDITOR
                return UniTask.FromResult(AssetBundle.LoadFromFile(path));
#else
                return AssetBundle.LoadFromFileAsync(path).ToUniTask();
#endif
            }
        }
    }
}
